var href = decodeURI(location.href)
console.log(href);
var area = document.querySelector(".area")
var shop = document.querySelector(".shop")
var place = document.querySelector(".place")
var product = document.querySelector(".product")
var flag = false
var shopId = []
var areaId = []
//获取标题
fetch("http://chst.vip:1234/api/getgsshop")
.then(data=>{
    return data.json();
})
.then(res1=>{
    //console.log(res1);
    console.log(res1.result);
    var shopname = res1.result.shopName;
    console.log(shopname);
    let ele1 = "";
    res1.result.forEach(item1 => {
        ele1 += `<li shopId="${item1.shopId}">${item1.shopName}</li>`
        shopId.push(item1.shopId)
    });
    
    shop.onclick = function(){
        area.innerHTML = ele1
        if(flag){
            area.style.display = "none";
            flag = false;
        }else{
            area.style.display = "block";
            flag = true;
        }
        console.log(this.shopId);
    }
    fetch("http://chst.vip:1234/api/getgsshoparea")
    .then(data=>{
        return data.json();
    })
    .then(res2=>{
        //console.log(res2);
        console.log(res2.result);
        let ele2 = "";
        res2.result.forEach(item2=>{
            ele2 += `<li areaId="${item2.areaId}">${item2.areaName}</li>`
            areaId.push(item2.areaId)
        })
        place.onclick = function(){
            area.innerHTML = ele2;
            if(flag){
                area.style.display = "none";
                flag = false;
            }else{
                area.style.display = "block";
                flag = true;
            }
        }
    }) 
    
})  
    console.log(shopId);
    console.log(areaId);
    fetch(`http://chst.vip:1234/api/getgsproduct?shopid=0&areaid=0`)
    .then(data=>{
        return data.json();
    })
    .then(res3=>{
        console.log(res3);
        console.log(res3.result);
        let ele3 = "";
        res3.result.forEach(item3=>{
            ele3 += `<li>
                        <a href="">
                            <img src="${item3.productImg}" alt="">
                            <p>${item3.productName}</p>
                            <span>${item3.productPrice}</span>
                        </a>
                    </li>`
        })
        product.innerHTML = ele3
})


